package com.chapter01exercise.homework11;

/**
 * @Author 小闽
 * @Date 2024/8/17 16:26
 * @PackageName: com.chapter01exercise.homework11
 * @ClassName: Homework11
 * @Description: 练习11
 * @Version 1.0
 */
public class Homework11 {
    /**
     * 现有Person类，里面有方法run、eat、Student类继承了Person类，并重写了run方法，自定义了study方法
     * 试写出对象向上转型和向下转型的代码，并写出各自都可以调用哪些方法，并写出方法输出什么？
     * class Person{
     *     public void run() {
     *              System.out.println("person run");
     *     }
     *     public void eat() {
     *              System.out.println("person eat);
     *     }
     * }
     * class Student extends Person {
     *     public void  run() {
     *          System.out.println("student run);
     *     }
     *     public void study() {
     *         System.out.println("student study...")
     *     }
     * }
     *
     */
    public static void main(String[] args) {
        /**
         * 向上转型
         */
        Person person = new Student();
        person.run();
        person.eat();
        /**
         * 向下转型
         */
        Student student = (Student) person;
        student.run();
        student.eat();
        student.eat();
        ((Student) person).study();
    }
}
